#include <iostream>
using namespace std;

/*
	重载++
	自增运算有两种
	     a++
		 ++a
*/

class Cat
{
public:
	Cat(int _age=0)
	{
		age=_age;
	}
	//搞定后置的++
	/*
		人类的思维习惯
		    Cat c2=c1++; 
		函数调用
		    Cat c2=c1.operator++(); //成员函数的理解
			Cat c2=operator++(c1);  //友元函数的理解
	*/
	//error: no ‘operator++(int)’ declared for postfix ‘++’ 
	//错误原因：后置的++添加int类型的参数为了跟前置的++区别
	Cat operator++(int n)
	{
		cout<<"后置的++重载被调用"<<endl;
		Cat temp;
		//先备份当前对象的值
		temp.age=this->age;
		//当前对象的值自己加1
		this->age+=1;
		return temp;
	}
	Cat operator++()
	{
		cout<<"前置的++重载被调用"<<endl;
		//当前对象的值自己加1
		this->age+=1;
		return *this;
	}
	
	void show()
	{
		cout<<"年龄: "<<age<<endl;
	}
private:
	int age;
};

int main()
{
	Cat c1(5);
	//写法1：后置的++
	// Cat c2=c1++; 
	// c1.show();  //6
	// c2.show();  //5
	
	//前置的++
	// Cat c3=++c1;  
	// c1.show(); //7
	// c3.show(); //7
	
	//写法2：函数调用的写法
	Cat c2=c1.operator++(666);
	c1.show();  //6
	c2.show();  //5
	
	Cat c3=c1.operator++();  
	c1.show();  //7
	c3.show();  //7
}